#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

int max(int a, int b)
{
    return (a > b) ? a : b;
}

int main()
{
    int n;
    scanf("%d", &n);
    getchar();

    int arr[100001];
    for (int i = 0; i < n; i++)
        scanf("%d", &arr[i]);

    int current_max = arr[0];
    int all_max = arr[0];
    for (int i = 1; i < n; i++)
    {
        current_max = max(current_max + arr[i], arr[i]);
        all_max = (all_max > current_max) ? all_max : current_max;
    }
    printf("%d", all_max);
    return 0;
}